package com.think.controller;

import com.alibaba.fastjson.JSONObject;
import com.think.dao.OrderMapper;
import com.think.entity.TOrder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Jason
 * @Date: 2021/03/11/18:25
 * @Description:
 */
@RestController
@Slf4j
@Api(value = "TestController服务", tags = "TestController服务")
public class TestController {
	
	@Resource
	private OrderMapper orderMapper;
	
	/**
	 * 刷新库存缓存
	 *
	 * @param
	 * @return
	 * @throws Exception
	 */
	@GetMapping(value = "/v1/api/test/{userId}/{orderId}")
	@ApiOperation(value = "test")
	public String test(@PathVariable("userId") int userId, @PathVariable("orderId") int orderId)  {
		try {
			TOrder order = new TOrder();
			order.setUserId(userId);
			order.setOrderId(orderId);
			orderMapper.insert(order);
			return "ok";
		} catch (Exception e) {
			log.error("测试失败,", e.getMessage(), e.fillInStackTrace());
			return "fail";
		}
	}
	
	@GetMapping(value = "/v1/api/test/{id}")
	@ApiOperation(value = "test")
	public String query(@PathVariable("id") int id)  {
		TOrder order = orderMapper.findById(id);
		if (order != null)
		System.out.println(order.getOrderId() + " " + order.getUserId());
		return JSONObject.toJSONString(order);
	}
}
